﻿using BrnMall.Manager.Domain.Blog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Manager.Manager.Blog
{
    
    public class BlogCommentManager
    {
        static string TableName = "crm_blogComment";

        /// <summary>
        /// 添加一条动态贴
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static bool Insert(BlogComment Model)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(Model);
            }
            return Model.Id > 0;
        }

        /// <summary>
        /// 查询动态贴评论列表
        /// </summary>
        public static IList<BlogComment> GetByBlogId(int Blogid)
        {
            string sql = string.Format("select * from crm_BlogComment where BlogId={0} order by Addtime", Blogid);
            using (var db = new QDMallDatabase())
            {
                return db.Fetch<BlogComment>(sql);
            }
        }

        public static IList<BlogComment> GetList(int blogid, int pageSize = 20)
        {
            string sql = string.Format("select top {0} * from {1} where BlogId={2} order by id", pageSize, TableName, blogid);
            using (var db = new QDMallDatabase())
            {
                return db.Fetch<BlogComment>(sql);
            }
        }


        /// <summary>
        /// 删除动态贴评论
        /// </summary>
        /// <param name="Msgid"></param>
        /// <returns></returns>
        public static bool DeleteByBlogId(int id)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Execute("delete crm_BlogComment where id=@0", id);
            }
            return count > 0 ? true : false;
        }      
    }
}